package com.zxl.app.config;

import com.zxl.app.interceptor.ApiTokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author zxw
 * @date 2023/4/1
 */
@Configuration
public class WebMvbConfig implements WebMvcConfigurer {

    @Resource
    private ApiTokenInterceptor apiTokenInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册Sa-Token的路由拦截器
        registry.addInterceptor(apiTokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/doc.html") //不需要拦截的地
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/v2/**")
                .excludePathPatterns("/favicon.ico")
                .excludePathPatterns("/swagger-ui.html/**","/doc.html/**")
                .excludePathPatterns("/app/goods/**","/app/goods_type/**")
                .excludePathPatterns("/wx/user/**","/app/common/**","/app/sms/**","/app/order/pay_notice",
                                     "/app/information/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/favicon.ico")
                .addResourceLocations("classpath:/static/");
    }

}
